<?php


	/*
	$tags = array();
	$tags[] = array('name'=>'abc','link'=>'xyz');
	
	*/
	function tagsAddContent($content, $tags){
		//$tags = _tagsFilter($tags);
		foreach($tags as $tag){
			$content= preg_replace('/((?!<[^>]*>)('.preg_quote($tag['name']).')(?![^<]*<\/) | (?!<[^>]*>)('.preg_quote($tag['name']).')(?![^<]*<\/))/i',$tag['link'], $content,1);
		}
		return $content;
	}
	
	//remove same tag
	function _tagsFilter($tags = array()){
		$arr_data = array();
		for($i=0; $i<count($tags); $i++){
			//co danh dau la tim thay hay khong
			$flag = 0;
			for($j=0; $j<count($tags); $j++){
			if($i == $j)
				continue;
				//if tim thay
				if(stripos($tags[$j]['name'],$tags[$i]['name']) != false){
					$flag = 1;
					break;
				}
				else {
				}
			}

			if($flag ==0){
				$arr_data[] = $tags[$i];
			}
		}
		return $arr_data;
	}


?>